from pymongo import MongoClient

conn_mongo = MongoClient('10.188.188.22', 27017)
db = conn_mongo.eLMSG

for item in db.eLMSG_1112.find({"LMSG_ID": "MSG003733"}):
    new_item1 = item
    print(new_item1)
    if 'Morphology' in new_item1.keys():
        del new_item1['Morphology']
    if 'Physiology' in new_item1.keys():
        del new_item1['Physiology']
    if 'Biochemistry' in new_item1.keys():
        del new_item1['Biochemistry']
    if 'Enzymology' in new_item1.keys():
        del new_item1['Enzymology']

    shape = {}
    shape['ID_reference '] = int(22117)
    shape['cell_shape'] = 'rod-shaped'
    new_item1.setdefault('Morphology', {}).setdefault('cell_shape', []).append(shape)
    size = {}
    size['ID_reference'] = int(22117)
    size['cell_len'] = '3.6-5.1'
    size['cell_len_unit'] = 'µm'
    size['cell_width'] = '0.8-0.9'
    size['cell_width_unit'] = 'µm'
    new_item1.setdefault('Morphology', {}).setdefault('cell_size', []).append(size)
    mo = {}
    mo['ID_reference'] = int(22117)
    mo['motility'] = True
    new_item1.setdefault('Morphology', {}).setdefault('motility', []).append(mo)
    arr = {}
    arr['ID_reference'] = int(22117)
    arr['flagellum_arr'] = 'peritrichous'
    new_item1.setdefault('Morphology', {}).setdefault('flagellum_arr', []).append(arr)
    # new_item.setdefault('Morphology', {}).setdefault('motility', []).append(shape_size['motility'])
    # new_item.setdefault('Morphology', {}).setdefault('flagellum_arr', []).append(shape_size['flagellum_arrangement'])
    spore_form = {}
    spore_form['ID_reference'] = int(22117)
    spore_form['ability'] = False
    spore_form['type'] = None
    spore_form['description'] = None
    new_item1.setdefault('Morphology', {}).setdefault('spore_form', []).append(spore_form)

    multicellular = {}
    multicellular['ability'] = False
    multicellular['medium_name'] = '5006'
    multicellular['multicell_name'] = None
    multicellular['multicell_size'] = None
    multicellular['multicell_size_unit'] = None
    multicellular['multicell_color'] = None
    multicellular['description'] = None
    new_item1.setdefault('Morphology', {}).setdefault('multicellular_morphology', []).append(multicellular)

    pigmentation = {}
    pigmentation['pigment_name'] = 'light brown'
    pigmentation['pigment_color'] = 'lemon-pigmented'
    new_item1.setdefault('Morphology', {}).setdefault('pigmentation', []).append(pigmentation)

    colony_morphology = {}
    colony_morphology['colony_len'] = None
    colony_morphology['colony_len_unit'] = None
    colony_morphology['colony_color'] = 'Zinc yellow (1018)'
    colony_morphology['colony_shape'] = None
    colony_morphology['medium_name'] = "5006"
    colony_morphology['medium_composition'] = "BC_cm_medium composition"
    colony_morphology['hemolysis_ability'] = None
    colony_morphology['hemolysis_type'] = None
    colony_morphology['incubation_period'] = "10-14 days"
    new_item1.setdefault('Morphology', {}).setdefault('colony_morphology', []).append(colony_morphology)

    murein = {}
    murein['murein_short_index'] = 'A11.54'
    murein['murein_types'] = 'A4alpha L-Lys-L-Glu'
    new_item1.setdefault('Morphology', {}).setdefault('murein', []).append(murein)

    culture_medium = {}
    culture_medium['medium_name'] = "RICH MEDIUM (DSMZ Medium 736), 28°C"
    culture_medium['medium_growth'] = True
    culture_medium['media_link'] = "https://www.dsmz.de/microorganisms/medium/pdf/DSMZ_Medium736.pdf"
    culture_medium['medium_composition'] = 'BC_medium_composition'
    new_item1.setdefault('Physiology', {}).setdefault('culture_medium', []).append(culture_medium)

    observation = {}
    observation['attribute'] = "Deacylation of benzyl- and phenoxymethyl penicillin tetrazoles"
    new_item1.setdefault('Physiology', {}).setdefault('observation', []).append(observation)

    antibiotica = {}
    antibiotica['ID_reference'] = int(22117)
    antibiotica['metabolite_antib'] = 'Paromomycin sulfate'
    antibiotica['ab_intermediate'] = True
    antibiotica['ab_intermediate_conc'] = '2-10'
    antibiotica['ab_intermediate_unit'] = 'µg/mL'
    new_item1.setdefault('Physiology', {}).setdefault('met_antibiotica', []).append(antibiotica)

    met_antibiogram = {}
    met_antibiogram['ID_reference'] = int(22117)
    met_antibiogram['Medium_antibiogram'] = '9191.0'
    met_antibiogram['Inc_temp_antibiogram'] = "Mueller-Hinton Agar"
    met_antibiogram['Inc_time_antibiogram'] = "EF_met_antibiogram"
    new_item1.setdefault('Physiology', {}).setdefault('met_antibiogram', []).append(met_antibiogram)

    nutrition_type = {}
    nutrition_type['nutrition_type'] = "chemolithoautotroph"
    new_item1.setdefault('Physiology', {}).setdefault('nutrition_type', []).append(nutrition_type)

    met_production = {}
    met_production['metabolite_prod'] = "2-Dehydro-D-gluconate"
    met_production['production'] = False
    met_production['excreted'] = None
    new_item1.setdefault('Physiology', {}).setdefault('met_production', []).append(met_production)

    tolerance = {}
    tolerance['compound_name'] = "Ethanol"
    tolerance['level_percent'] = "10"
    tolerance['concentration'] = None
    tolerance['concentration_unit'] = None
    new_item1.setdefault('Physiology', {}).setdefault('tolerance', []).append(tolerance)

    oxygen = {}
    oxygen['oxygen_tol'] = "obligate aerobe"
    new_item1.setdefault('Physiology', {}).setdefault('oxygen', []).append(oxygen)

    gram_tmp = {}
    gram_tmp['ID_reference'] = int(22117)
    gram_tmp['gram'] = 'negative'
    new_item1.setdefault('Physiology', {}).setdefault('gram', []).append(gram_tmp)

    growth_temp = {}
    growth_temp['test_type'] = "optimum"
    growth_temp['temp'] = "28"
    growth_temp['temperature_range'] = "mesophilic"
    growth_temp['ability'] = "positive"
    new_item1.setdefault('Physiology', {}).setdefault('growth_temp', []).append(growth_temp)

    growth_ph = {}
    growth_ph['ability'] = "inconsistent"
    growth_ph['test_type'] = "growth"
    growth_ph['pH'] = "6.0"
    new_item1.setdefault('Physiology', {}).setdefault('growth_ph', []).append(growth_ph)

    halophily = {}
    halophily['salt'] = "NaCl"
    halophily['test_type'] = "maximum"
    halophily['salt_concentration'] = "5"
    halophily['salt_concentration_unit'] = "%"
    halophily['ability'] = "positive"
    halophily['halophily'] = None
    new_item1.setdefault('Physiology', {}).setdefault('halophily', []).append(halophily)

    cn_source = {}
    cn_source['metabolite_util'] = "Maltose"
    cn_source['ability'] = "-"
    cn_source['test_type'] = "carbon source"
    new_item1.setdefault('Physiology', {}).setdefault('cn_source', []).append(cn_source)

    gc = {}
    gc['GC_content'] = "71.4"
    gc['GC_method '] = "high pressure liquid chromatography (HPLC)"
    new_item1.setdefault('Physiology', {}).setdefault('gc', []).append(gc)

    sensitive = {}
    sensitive['ID_reference'] = int(22117)
    sensitive['metabolite_antib'] = 'Neomycin'
    sensitive['ab_sensitive'] = True
    sensitive['ab_sensitivity_conc'] = '0.5-1'
    sensitive['ab_sensitivity_unit'] = 'µg/mL'
    new_item1.setdefault('Physiology', {}).setdefault('antibiotic_s', []).append(sensitive)

    resistant = {}
    resistant['ID_reference'] = int(22117)
    resistant['metabolite_antib'] = 'Bacitracin'
    resistant['ab_resistant'] = True
    resistant['ab_resistance_conc'] = '10'
    resistant['ab_resistance_unit'] = 'Unit'
    new_item1.setdefault('Physiology', {}).setdefault('antibiotic_r', []).append(resistant)

    pathogenicity = {}
    pathogenicity['biosafety_level'] = "1"
    pathogenicity['biosafety_level_comment'] = "Risk group (German classification)"
    pathogenicity['pathogenicity_plant'] = None
    pathogenicity['pathogenicity_animal'] = None
    pathogenicity['pathogenicity_human'] = None
    new_item1.setdefault('Physiology', {}).setdefault('pathogenicity', []).append(pathogenicity)

    sequence = {}
    sequence['DB_sequence'] = "Marker Gene (EMBL Direct submission)"
    sequence[
        'Sequence_accession_title'] = "TPA: Beutenbergia cavernae DSM 12333 transfer-messenger mRNA Beute_caver_12333, single chain mature transcript"
    sequence['seq_acc_num'] = "HG788573"
    sequence['sequence_length'] = '368'
    sequence['NCBI_tax_ID'] = '471853'
    sequence['NCBI_Gi'] = '559132476'
    sequence['text_mined'] = True
    new_item1.setdefault('Physiology', {}).setdefault('sequence', []).append(sequence)

    nitrate_rdc = {}
    nitrate_rdc['nitrate_rdc'] = False
    new_item1.setdefault('Biochemistry', {}).setdefault('nitrate_rdc', []).append(nitrate_rdc)

    test_tmp = {}
    test_tmp['ID_reference'] = int(22117)
    test_tmp['indole_pdu'] = '-'
    new_item1.setdefault('Biochemistry', {}).setdefault('indole_pdu', []).append(test_tmp)

    vp = {}
    vp['ID_reference'] = int(22117)
    vp['vp_test'] = '+'
    new_item1.setdefault('Biochemistry', {}).setdefault('vp_test', []).append(vp)

    h2s_pdu = {}
    h2s_pdu['h2s_pdu'] = 'H2S was produced from yeast extract'
    new_item1.setdefault('Biochemistry', {}).setdefault('h2s_pdu', []).append(h2s_pdu)

    milk_pep = {}
    milk_pep['milk_pep'] = 'positive'
    new_item1.setdefault('Biochemistry', {}).setdefault('milk_pep', []).append(milk_pep)

    milk_cog = {}
    milk_cog['milk_cog'] = 'negative'
    new_item1.setdefault('Biochemistry', {}).setdefault('milk_cog', []).append(milk_cog)

    citrate = {}
    citrate['ID_reference'] = int(22117)
    citrate['citrate_utl'] = '+'
    new_item1.setdefault('Biochemistry', {}).setdefault('citrate_utl', []).append(citrate)

    metylred = {}
    metylred['ID_reference'] = int(22117)
    metylred['metylred_test'] = '-'
    new_item1.setdefault('Biochemistry', {}).setdefault('metylred_test', []).append(metylred)

    gelatin_hyd = {}
    gelatin_hyd['gelatin_hyd'] = False
    new_item1.setdefault('Biochemistry', {}).setdefault('gelatin_hyd', []).append(gelatin_hyd)

    fattyacids = {}
    fattyacids['fattyacids'] = 'The main fatty acids are iso-C 15 : 0, anteiso-C 15 : 0 and C 16 : 0'
    new_item1.setdefault('Biochemistry', {}).setdefault('fattyacids', []).append(fattyacids)

    polarlipid = {}
    polarlipid['polarlipid'] = 'phosphatidylethanolamine'
    new_item1.setdefault('Biochemistry', {}).setdefault('polarlipid', []).append(polarlipid)

    quinones = {}
    quinones['quinones'] = 'menaquinone;MK-7'
    new_item1.setdefault('Biochemistry', {}).setdefault('quinones', []).append(quinones)

    wholecell_sugar = {}
    wholecell_sugar['wholecell_sugar'] = 'madurose'
    new_item1.setdefault('Biochemistry', {}).setdefault('wholecell_sugar', []).append(wholecell_sugar)

    cellwall_sugar = {}
    cellwall_sugar['cellwall_sugar'] = 'arabinose'
    new_item1.setdefault('Biochemistry', {}).setdefault('cellwall_sugar', []).append(cellwall_sugar)

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.1.3.2"
    new_item1.setdefault('Enzymology', {})['acid_phosphatase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.1.3.1"
    new_item1.setdefault('Enzymology', {})['alkaline_phosphatase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.5.3.6"
    new_item1.setdefault('Enzymology', {})['arginine_dihydrolase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "1.11.1.6"
    new_item1.setdefault('Enzymology', {})['catalase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.4.11.3"
    new_item1.setdefault('Enzymology', {})['cystine_arylamidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = None
    new_item1.setdefault('Enzymology', {})['esterase_C4'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = None
    new_item1.setdefault('Enzymology', {})['esterase_Lipase_C8'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.4.11.1"
    new_item1.setdefault('Enzymology', {})['leucine_arylamidas'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = None
    new_item1.setdefault('Enzymology', {})['lipase_C14'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "4.1.1.18"
    new_item1.setdefault('Enzymology', {})['lysine_decarboxylase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.52"
    new_item1.setdefault('Enzymology', {})['N_acetyl_beta_glucosaminidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = None
    new_item1.setdefault('Enzymology', {})['naphthol_AS_BI_phosphohydrolase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "4.1.1.17"
    new_item1.setdefault('Enzymology', {})['ornithine_decarboxylase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "1.9.3.1"
    new_item1.setdefault('Enzymology', {})['cytochrome_c_oxidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.4.21.4"
    new_item1.setdefault('Enzymology', {})['trypsin'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "4.1.99.1"
    new_item1.setdefault('Enzymology', {})['tryptophan_deaminase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.5.1.5"
    new_item1.setdefault('Enzymology', {})['urease'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = None
    new_item1.setdefault('Enzymology', {})['valine_arylamidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "+"
    enzyme['ec_number'] = "3.4.21.1"
    new_item1.setdefault('Enzymology', {})['alpha_chymotrypsin'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.51"
    new_item1.setdefault('Enzymology', {})['alpha_fucosidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.22"
    new_item1.setdefault('Enzymology', {})['alpha_galactosidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.20"
    new_item1.setdefault('Enzymology', {})['alpha_glucosidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.24"
    new_item1.setdefault('Enzymology', {})['alpha_mannosidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.23"
    new_item1.setdefault('Enzymology', {})['beta_galactosidase'] = enzyme

    enzyme = {}
    enzyme['activity'] = "-"
    enzyme['ec_number'] = "3.2.1.21"
    new_item1.setdefault('Enzymology', {})['beta_glucosidase'] = enzyme

    new_item1['environment_sampling_isolation_source'] = item['environment_sampling_isolation_source']
    new_item1['strain_availability'] = item['strain_availability']
    new_item1['LMSG_ID'] = 'MSG100001'
    print(new_item1)

    db.eLMSG_1112.save(new_item1)
